<template>
  <div class="box">
    <SearchVue class="search"></SearchVue>
    <div class="content">
      <BannerBarVue></BannerBarVue>
      <NavBarVue></NavBarVue>
      <SeckillVue></SeckillVue>
      <DetailsVue></DetailsVue>
      <div class="backTop" @click="backTop" v-show="flag_scroll">
        <van-icon name="back-top" class="back" />
      </div>
    </div>
    <FooterBarVue class="footer"></FooterBarVue>
  </div>
</template>

<script>
import SearchVue from '@/components/Search.vue';
import BannerBarVue from '@/components/BannerBar.vue';
import NavBarVue from '@/components/NavBar.vue';
import SeckillVue from '@/components/Seckill.vue';
import DetailsVue from '@/components/Details.vue';
import FooterBarVue from '@/components/FooterBar.vue';
export default {
    name:"Home",
    components:{
        SearchVue,NavBarVue,DetailsVue,BannerBarVue,SeckillVue,FooterBarVue
    },
    data() {
      return {
        flag_scroll: false
      }
    },
    mounted() {
    // 监听滚动事件
    document.querySelector(".box").addEventListener('scroll', this.handleScroll, true)
  },
  methods:{
    backTop() {
      document.querySelector(".content").scrollTop = 0;
    },
    handleScroll(){
      let scrollTop = document.querySelector(".content").scrollTop;
      if (scrollTop > 380) {
        this.flag_scroll = true;
      } else {
        this.flag_scroll = false;
      }
    } 
  }
}
</script>

<style scoped>
  .box {
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: space-between;
  }
  .content {
    flex: 1;
    overflow: auto;
    /* position: relative; */
  }
  .backTop {
    position: fixed;
    right: 2.25rem;
    top: 35.875rem;
    border-radius: 50%;
    background-color: yellow;
  }
  .back{
    font-size: 1.875rem;
    color: black;
  }
</style>